package com.example.websocket.controller;

import com.example.websocket.config.base.CommonResult;
import com.example.websocket.domain.UserDto;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class IndexController {

    @GetMapping("user")
    public CommonResult getUser() {
        LocalDate localDate = LocalDate.of(2025, 10, 1);
        UserDto userDto = new UserDto();
        userDto.setId(1);
        userDto.setUserType(1);
        userDto.setName("张三");
        userDto.setBirthDate2(Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
        userDto.setBirthDate(LocalDateTime.now());
        return CommonResult.ok(userDto);
//        return userDto;
    }

    @GetMapping("users")
    public CommonResult getUsers() {
        List<UserDto> users = new ArrayList<>();
        for (int i = 1; i <= 2; i++) {
            LocalDate localDate = LocalDate.of(2025, 10, 1);
            UserDto userDto = new UserDto();
            userDto.setId(i);
            userDto.setUserType(i);
            userDto.setName("张三" + i);
            userDto.setBirthDate2(Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()));
            userDto.setBirthDate(LocalDateTime.now());
            users.add(userDto);
        }
        return CommonResult.ok(users);
    }

}
